public class test10 {
    public int[] sortedSquares(int[] nums) {
        //非暴力方法，利用双指针法
        int left = 0,right = nums.length-1;
        int[] res = new int[nums.length];
        int i = res.length-1;
        while(left<=right){
            if(nums[left]*nums[left]>=nums[right]*nums[right]){
                res[i] = nums[left]*nums[left];
                left++;
            }else{
                res[i] = nums[right]*nums[right];
                right--;
            }
            i--;
        }
        return res;
    }
}
